# Copyright 2009 http://www.yuntien.com
# Licensed under the Apache License, Version 2.0

from ytblog.controller.common import *
from ytblog.controller.blog_add import *

class BlogEditController(BlogAddController):

  def render(self, context):
    path = os.path.join(os.path.dirname(__file__), ytblog.config.TEMPLATE_DIR + 'edit.html')
    self.response.out.write(template.render(path, context))   
  
  #display edit blog ui
  @check_blog_id
  @authorize(Blog, authorization.OPERATION_EDIT)
  def get(self, id):
    blog = Blog.get_by_str_id(id)
    blog.blog_tag = blog.get_tag_str()
    
    context = { 'blog': blog }
    self.add_common_context(context)
    self.render(context)
  
  # post a new blog
  @check_tag
  @check_blog_id
  @authorize(Blog, authorization.OPERATION_EDIT)
  def post(self, id):    
    blog = Blog.get_by_str_id(id)
    self.fill_data(blog)
    blog.put()

    self.redirect(ytblog.config.CONFIG['url_blog'] + '/' + id + '/')    
